﻿package idv.cjcat.monica.platformer.player {
	import idv.cjcat.rusher.engine.logger.LogType;
	import idv.cjcat.rusher.geom.Vec2D;
	
	internal class JumpingUpDashingState extends PlayerState {
		
		public function JumpingUpDashingState(controller:PlayerController, direction:Number) {
			super(controller, direction);
			controller.engine.logger.log("Entered state: JumpingUpDashingState", LogType.INFO, controller);
			
			var vel:Vec2D = getVelocity();
			vel.y = -PlayerController.JUMP_BOOST;
			setVelocity(vel);
			
			controller.jumpCount++;
			
			controller.engine.soundManager.play(new SFXJump());
		}
		
		override public function stopJump():void {
			var vel:Vec2D = getVelocity();
			vel.y *= PlayerController.JUMP_CANCEL_FACTOR;
			setVelocity(vel);
			
			setState(FallingDownDashingState);
			setPlayerMovieClip(renderTarget.fallingDownRoll, false);
		}
		
		override public function onTick(time:Number):void {
			var vel:Vec2D = getVelocity();
			
			if (vel.y > 0 && !controller.onFloor) {
				setState(FallingDownDashingState);
				setPlayerMovieClip(renderTarget.fallingDownRoll, false);
				return;
			}
			
			if (controller.moving) {
				if (controller.onWall) vel.x = 0;
				else vel.x = controller.direction * PlayerController.RUNNING_SPEED;
			} else {
				vel.x = 0;
			}
			setVelocity(vel);
		}
	}
}